﻿using System;
using System.Web.Services;
using Monkey.Warrenty.Biz;
using Monkey.Warrenty.EntityModel;

namespace MonkeyWarranty.Web.Suppliers
{
    public partial class List : System.Web.UI.Page
    {
        #region Properties

        private static SupplierBiz _supplierBiz;
        private static SupplierBiz SupplierManager
        {
            get { return _supplierBiz ?? (_supplierBiz = new SupplierBiz()); }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var groups = SupplierManager.GetAllSupplierGroups();//_repository.CityRepository.GetAllCustomerGroups();
                groups.Insert(0, new SupplierGroup { Id = 0, Name = Resources.GlobalStrings.AllGroups });

                ddlSupplierGroups.DataTextField = "Name";
                ddlSupplierGroups.DataValueField = "Id";
                ddlSupplierGroups.DataSource = groups;
                ddlSupplierGroups.DataBind();
            }
        }

        #region Supplier methods

        [WebMethod(EnableSession = true)]
        public static object SupplierListByFilter(string name, int supplierGroupId, int jtStartIndex, int jtPageSize, string jtSorting)
        {
            return SupplierManager.SupplierListByFilterWs(name, supplierGroupId, jtStartIndex, jtPageSize, jtSorting);
        }

        [WebMethod(EnableSession = true)]
        public static object CreateSupplier(Supplier record)
        {
            return SupplierManager.CreateSupplierWs(record);
        }

        [WebMethod(EnableSession = true)]
        public static object UpdateSupplier(Supplier record)
        {
            return SupplierManager.UpdateSupplierWs(record);
        }

        [WebMethod(EnableSession = true)]
        public static object DeleteSupplier(int Id)
        {
            return SupplierManager.DeleteSupplierWs(Id);
        }

        #endregion

        #region CusmtomerGroup methods

        [WebMethod(EnableSession = true)]
        public static object GetSupplierGroupOptions()
        {
            return SupplierManager.GetSupplierGroupOptionsWs();
        }

        #endregion
    }
}